package nf.action;

import nf.dao.CellPhoneDao;
import nf.dao.CellPhoneDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/deleteServlet")
public class deleteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        String username =(String)session.getAttribute("username");
        String password =(String)session.getAttribute("password");

        if(username!=null||password!=null) {
            Integer id = Integer.parseInt(request.getParameter("id"));

            CellPhoneDao dao = new CellPhoneDaoImpl();
            dao.deleteById(id);
            response.sendRedirect("ServletPhone");
        }else {
            response.sendRedirect("index.jsp");
        }
    }
}
